package com.example.javaproject;

public abstract class CommonAction<T, R> {
    CommonAction<R, ?> nextAction;

    public CommonAction() {
    }

    public CommonAction(CommonAction<R, ?> action) {
        this.nextAction = action;
    }

    abstract R invoke(T t);

    public R doNext(T t) {
        R r = invoke(t);
        if (nextAction != null) {
            return (R) nextAction.doNext(r);
        }
        return r;
    }

}
